#!/usr/bin/env python3
"""
Analyze the connection between dcu_performance_test.cpp and hip_stream_test.cpp
"""

import os

def analyze_file_content(filename):
    """Read and analyze file content"""
    try:
        with open(filename, 'r') as f:
            content = f.read()
        return content
    except FileNotFoundError:
        return f"File {filename} not found"

def extract_key_components(content, filename):
    """Extract key components from file content"""
    lines = content.split('\n')
    
    # Find key sections
    kernel_functions = []
    test_functions = []
    main_function = []
    
    in_kernel = False
    in_test = False
    
    for i, line in enumerate(lines):
        if '__global__' in line:
            kernel_functions.append(f"Line {i+1}: {line.strip()}")
            in_kernel = True
        elif line.strip().startswith('double test') or line.strip().startswith('PerformanceMetrics test'):
            test_functions.append(f"Line {i+1}: {line.strip()}")
            in_test = True
        elif 'int main' in line:
            main_function.append(f"Line {i+1}: {line.strip()}")
    
    return {
        'filename': filename,
        'total_lines': len(lines),
        'kernel_functions': kernel_functions,
        'test_functions': test_functions,
        'main_function': main_function
    }

def main():
    files = [
        '/home/linden/test-stream/dcu_performance_test.cpp',
        '/home/linden/test-stream/hip_stream_test.cpp'
    ]
    
    print("=== Connection Analysis: dcu_performance_test.cpp vs hip_stream_test.cpp ===\n")
    
    for filename in files:
        print(f"Analyzing {os.path.basename(filename)}:")
        print("=" * 60)
        
        content = analyze_file_content(filename)
        if "not found" in content:
            print(content)
            continue
            
        analysis = extract_key_components(content, filename)
        
        print(f"File: {analysis['filename']}")
        print(f"Total lines: {analysis['total_lines']}")
        
        print("\nKernel Functions found:")
        for kernel in analysis['kernel_functions']:
            print(f"  {kernel}")
            
        print("\nTest Functions found:")
        for test in analysis['test_functions']:
            print(f"  {test}")
            
        print("\nMain Function:")
        for main in analysis['main_function']:
            print(f"  {main}")
            
        print("\n" + "=" * 60 + "\n")

if __name__ == "__main__":
    main()